package smarties.info.panel;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.List;

import com.visutools.nav.bislider.BiSlider;
import com.visutools.nav.bislider.ContentPainterEvent;
import com.visutools.nav.bislider.ContentPainterListener;

/**
 * Permet l'affichage (pas le calcul) de la distribution dans la bislider
 * 
 * @author buthane
 */
public class BiSliderPainterListener implements ContentPainterListener
{
	private List<Double>	ratioList;

	public void setRatioList(List<Double> ratioList)
	{
		synchronized (this)
		{
			this.ratioList = ratioList;
		}
	}

	public void paint(ContentPainterEvent event)
	{
		double BarHeight;
		synchronized (this)
		{
			BarHeight = 1;
			if (this.ratioList != null
					&& event.getSegmentIndex() < this.ratioList.size())
			{
				BarHeight = 1 - this.ratioList.get(event.getSegmentIndex());
			}
		}

		BiSlider biSlider = (BiSlider) event.getSource();

		Graphics2D Graphics2 = (Graphics2D) event.getGraphics();
		Rectangle Rect = event.getBoundingRectangle();

		if (event.getColor() != null)
		{
			Graphics2.setColor(biSlider.getSliderBackground());
			Graphics2.setColor(event.getColor());
			Graphics2.fillRect(Rect.x, Rect.y
					+ (int) ((BarHeight * Rect.height)), Rect.width + 1,
					1 + (int) (((1 - BarHeight) * Rect.height)));
		}
		else
		{
			Graphics2.setColor(Color.LIGHT_GRAY);
			Graphics2.fillRect(Rect.x, Rect.y
					+ (int) ((BarHeight * Rect.height)), Rect.width + 1,
					1 + (int) (((1 - BarHeight) * Rect.height)));
		}
	}
}
